package com.paic.mhis.hcpms.agreement.protocol.biz.validator;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.common.validator.HcpmsBaseValidator;
import com.paic.mhis.common.validator.MapValidator;
import com.paic.mhis.common.validator.ValidatorList;
import com.paic.mhis.hcpms.agreement.protocol.util.DiseasePayValidatorConstants;
import com.paic.mhis.hcpms.agreement.protocol.util.ServiceItemPayValidatorConstans;
import com.paic.pafa.app.biz.bo.validation.ValidStatus;

@Component("diseasePayValidator")
public class DiseasePayValidator extends HcpmsBaseValidator {

	@Override
	public Map<Object, Object> validate(Map<Object, Object> fieldMap) {
		validatorList = new ValidatorList();
		validatorList.setValidateAll(true);

		// 常规验证
		validateFieldNotNull();
		validateNumber();
		validateFieldLengthLimit();

		ValidStatus validStatus = validatorList.validate(fieldMap);

		return throwErrorMassage(validStatus);
	}

	/* 验证非空字段 */
	private void validateFieldNotNull() {
		validatorList
				.add(MapValidator
						.require(
								DiseasePayValidatorConstants.DISEASE_NAME_REQUIRE_VALIDATE,
								DiseasePayValidatorConstants.DISEASE_NAME_REQUIRE_VALIDATE_MSG));
		validatorList
				.add(MapValidator
						.require(
								DiseasePayValidatorConstants.DISEASE__CODE_REQUIRE_VALIDATE,
								DiseasePayValidatorConstants.DISEASE_CODE_REQUIRE_VALIDATE_MSG));
		validatorList.add(MapValidator.require(
				DiseasePayValidatorConstants.PAY_AMOUT_REQUIRE_VALIDATE,
				DiseasePayValidatorConstants.PAY_AMOUT_REQUIRE_VALIDATE_MSG));
	}

	/* 验证长度限制字段 */
	private void validateFieldLengthLimit() {
		validatorList
				.add(MapValidator
						.maxLength(
								DiseasePayValidatorConstants.PAY_CONDITION_FROM_REQUIRE_LENGTH,
								120,
								DiseasePayValidatorConstants.PAY_CONDITION_FROM_REQUIRE_LENGTH_MSG));
		validatorList
				.add(MapValidator
						.maxLength(
								DiseasePayValidatorConstants.DISEASE__CODE_FROM_REQUIRE_LENGTH,
								32,
								ServiceItemPayValidatorConstans.DISCOUNTRATIO_NUMBER_REQUIRE_MSG));
	}

	/* 验证数字长度 */
	private void validateNumber() {
		validatorList.add(MapValidator.number(
				DiseasePayValidatorConstants.PAYAMOUNT_NUMBER_REQUIRE, 12, 2,
				DiseasePayValidatorConstants.PAYAMOUNT_NUMBER_REQUIRE_MSG));
	}
}
